home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Python 1.1 / Modules / cursesmodule.c < prev    next >
Encoding:
Text File  |  1994-09-14  |  36.8 KB  |  1,444 lines  |  [TEXT/KAHL]

  1. /***********************************************************
  2. Copyright 1994 by Lance Ellinghouse,
  3. Cathedral City, California Republic, United States of America.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the name of Lance Ellinghouse
  12. not be used in advertising or publicity pertaining to distribution 
  13. of the software without specific, written prior permission.
  14.  
  15. LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO
  16. THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS, IN NO EVENT SHALL LANCE ELLINGHOUSE BE LIABLE FOR ANY SPECIAL, 
  18. INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 
  19. FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 
  20. NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 
  21. WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. /******************************************************************
  26. This is a curses implementation. I have tried to be as complete
  27. as possible. If there are functions you need that are not included,
  28. please let me know and/or send me some diffs.
  29.  
  30. There are 3 basic types exported by this module:
  31.    1) Screen - This is not currently used
  32.    2) Window - This is the basic type. This is equivalent to "WINDOW *".
  33.    3) Pad    - This is similar to Window, but works with Pads as defined
  34.                in curses.
  35.  
  36. Most of the routines can be looked up using the curses man page.
  37.  
  38. Here is a list of the currently supported methods and attributes
  39. in the curses module:
  40.  
  41. Return Value      Func/Attr            Description
  42. --------------------------------------------------------------------------
  43. StringObject      __version__          This returns a string representing
  44.                                        the current version of this module
  45. WindowObject      initscr()            This initializes the screen for use
  46. None              endwin()             Closes down the screen and returns
  47.                                        things as they were before calling
  48.                                        initscr()
  49. True/FalseObject  isendwin()           Has endwin() been called?
  50. IntObject         doupdate()           Updates screen and returns number
  51.                                        of bytes written to screen
  52. WindowObject      newwin(nlines,ncols,begin_y,begin_x)
  53.                   newwin(begin_y,begin_x)
  54.                                        newwin() creates and returns
  55.                                        a new window.
  56. None              beep()               Beep the screen if possible
  57. None              flash()              Flash the screen if possible
  58. None              ungetch(int)         Push the int back so next getch()
  59.                                        will return it.
  60.                                        Note: argument is an INT, not a CHAR
  61. None              flushinp()           Flush all input buffers
  62. None              cbreak()             Enter cbreak mode
  63. None              nocbreak()           Leave cbreak mode
  64. None              echo()               Enter echo mode
  65. None              noecho()             Leave echo mode
  66. None              nl()                 Enter nl mode
  67. None              nonl()               Leave nl mode
  68. None              raw()                Enter raw mode
  69. None              noraw()              Leave raw mode
  70. None              intrflush(int)       Set or reset interruptable flush
  71.                                        mode, int=1 if set, 0 if notset.
  72. None              meta(int)            Allow 8 bit or 7 bit chars.
  73.                                        int=1 is 8 bit, int=0 is 7 bit
  74. StringObject      keyname(int)         return the text representation
  75.                                        of a KEY_ value. (see below)
  76.  
  77. Here is a list of the currently supported methods and attributes
  78. in the WindowObject:
  79.  
  80. Return Value      Func/Attr            Description
  81. --------------------------------------------------------------------------
  82. IntObject         refresh()            Do refresh
  83. IntObject         nooutrefresh()       Mark for refresh but wait
  84. True/False        mvwin(new_y,new_x)   Move Window
  85. True/False        move(new_y,new_x)    Move Cursor
  86. WindowObject      subwin(nlines,ncols,begin_y,begin_x)
  87.                   subwin(begin_y,begin_x)
  88. True/False        addch(y,x,ch,attr)
  89.                   addch(y,x,ch)
  90.                   addch(ch,attr)
  91.                   addch(ch)
  92. True/False        insch(y,x,ch,attr)
  93.                   insch(y,x,ch)
  94.                   insch(ch,attr)
  95.                   insch(ch)
  96. True/False        delch(y,x)
  97.                   delch()
  98. True/False        echochar(ch,attr)
  99.                   echochar(ch)
  100. True/False        addstr(y,x,str,attr)
  101.                   addstr(y,x,str)
  102.                   addstr(str,attr)
  103.                   addstr(str)
  104. True/False        attron(attr)
  105. True/False        attroff(attr)
  106. True/False        attrset(sttr)
  107. True/False        standend()
  108. True/False        standout()
  109. True/False        box(vertch,horch)    vertch and horch are INTS
  110.                   box()
  111. None              erase()
  112. None              deleteln()
  113. None              insertln()
  114. (y,x)             getyx()
  115. (y,x)             getbegyx()
  116. (y,x)             getmaxyx()
  117. None              clear()
  118. None              clrtobot()
  119. None              clrtoeol()
  120. None              scroll()
  121. None              touchwin()
  122. None              touchline(start,count)
  123. IntObject         getch(y,x)
  124.                   getch()
  125. StringObject      getstr(y,x)
  126.                   getstr()
  127. IntObject         inch(y,x)
  128.                   inch()
  129. None              clearok(int)      int=0 or int=1
  130. None              idlok(int)        int=0 or int=1
  131. None              leaveok(int)      int=0 or int=1
  132. None              scrollok(int)     int=0 or int=1
  133. None              setscrreg(top,bottom)
  134. None              nodelay(int)      int=0 or int=1
  135. None              notimeout(int)    int=0 or int=1
  136. ******************************************************************/
  137.  
  138.  
  139. /* curses module */
  140.  
  141. #include "Python.h"
  142.  
  143. #include <curses.h>
  144.  
  145. typedef struct {
  146.     PyObject_HEAD
  147.     SCREEN *scr;
  148. } PyCursesScreenObject;
  149.  
  150. typedef struct {
  151.     PyObject_HEAD
  152.     WINDOW *win;
  153.     WINDOW *parent;
  154. } PyCursesWindowObject;
  155.  
  156. typedef struct {
  157.     PyObject_HEAD
  158.     WINDOW *pad;
  159. } PyCursesPadObject;
  160.  
  161. staticforward PyTypeObject PyCursesScreen_Type;
  162. staticforward PyTypeObject PyCursesWindow_Type;
  163. staticforward PyTypeObject PyCursesPad_Type;
  164.  
  165. #define PyCursesScreen_Check(v)     ((v)->ob_type == &PyCursesScreen_Type)
  166. #define PyCursesWindow_Check(v)     ((v)->ob_type == &PyCursesWindow_Type)
  167. #define PyCursesPad_Check(v)     ((v)->ob_type == &PyCursesPad_Type)
  168.  
  169. /* Defines */
  170. PyObject *PyCurses_OK;
  171. PyObject *PyCurses_ERR;
  172.  
  173. /******************************************************************
  174.  
  175. Change Log:
  176.  
  177. Version 1.1: 94/08/31:
  178.     Minor fixes given by Guido.
  179.     Changed 'ncurses' to 'curses'
  180.     Changed '__version__' to 'version'
  181.     Added PyErr_Clear() where needed
  182.     Moved ACS_* attribute initialization to PyCurses_InitScr() to fix
  183.         crash on SGI
  184. Version 1.0: 94/08/30:
  185.     This is the first release of this software.
  186.     Released to the Internet via python-list@cwi.nl
  187.  
  188. ******************************************************************/
  189. char *PyCursesVersion = "1.1";
  190.  
  191. /* ------------- SCREEN routines --------------- */
  192. #ifdef NOT_YET
  193. static PyObject *
  194. PyCursesScreen_New(arg)
  195.     PyObject * arg;
  196. {
  197.         char *term_type;
  198.     PyFileObject *in_fo;
  199.     PyFileObject *out_fo;
  200.     PyCursesScreenObject *xp;
  201.     xp = (PyObject *)PyObject_NEW(PyCursesScreenObject, &PyCursesScreen_Type);
  202.     if (xp == NULL)
  203.         return NULL;
  204.     return (PyObject *)xp;
  205. }
  206. #endif
  207. /* ------------- WINDOW routines --------------- */
  208. static PyObject *
  209. PyCursesWindow_New(win)
  210.     WINDOW *win;
  211. {
  212.     PyCursesWindowObject *wo;
  213.     wo = (PyCursesWindowObject *)PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
  214.     if (wo == NULL)
  215.         return NULL;
  216.     wo->win = win;
  217.     wo->parent = (WINDOW *)NULL;
  218.     return (PyObject *)wo;
  219. }
  220.  
  221. static void
  222. PyCursesWindow_Dealloc(wo)
  223.     PyCursesWindowObject *wo;
  224. {
  225.   if (wo->win != stdscr)
  226.     delwin(wo->win);
  227.   PyMem_DEL(wo);
  228. }
  229.  
  230. static PyObject *
  231. PyCursesWindow_Refresh(self,arg)
  232.      PyCursesWindowObject *self;
  233.      PyObject * arg;
  234. {
  235.   if (!PyArg_NoArgs(arg))
  236.     return (PyObject *)NULL;
  237.   return (PyObject *)PyInt_FromLong(wrefresh(self->win));
  238. }
  239.  
  240. static PyObject *
  241. PyCursesWindow_NoOutRefresh(self,arg)
  242.      PyCursesWindowObject *self;
  243.      PyObject * arg;
  244. {
  245.   if (!PyArg_NoArgs(arg))
  246.     return (PyObject *)NULL;
  247.   return (PyObject *)PyInt_FromLong(wnoutrefresh(self->win));
  248. }
  249.  
  250. static PyObject *
  251. PyCursesWindow_MoveWin(self,arg)
  252.      PyCursesWindowObject *self;
  253.      PyObject * arg;
  254. {
  255.   int rtn;
  256.   int x, y;
  257.   if (!PyArg_Parse(arg,"(ii)", &y, &x))
  258.     return (PyObject *)NULL;
  259.   rtn = mvwin(self->win,y,x);
  260.   if (rtn == OK) {
  261.     Py_INCREF(PyCurses_OK);
  262.     return (PyObject *)PyCurses_OK;
  263.   }
  264.   Py_INCREF(PyCurses_ERR);
  265.   return (PyObject *)PyCurses_ERR;
  266. }
  267.  
  268. static PyObject *
  269. PyCursesWindow_Move(self,arg)
  270.      PyCursesWindowObject *self;
  271.      PyObject * arg;
  272. {
  273.   int rtn;
  274.   int x, y;
  275.   if (!PyArg_Parse(arg,"(ii)", &y, &x))
  276.     return (PyObject *)NULL;
  277.   rtn = wmove(self->win,y,x);
  278.   if (rtn == OK) {
  279.     Py_INCREF(PyCurses_OK);
  280.     return (PyObject *)PyCurses_OK;
  281.   }
  282.   Py_INCREF(PyCurses_ERR);
  283.   return (PyObject *)PyCurses_ERR;
  284. }
  285.  
  286. static PyObject *
  287. PyCursesWindow_SubWin(self,arg)
  288.      PyCursesWindowObject *self;
  289.      PyObject * arg;
  290. {
  291.   WINDOW *win;
  292.   PyCursesWindowObject *rtn_win;
  293.   int nlines, ncols, begin_y, begin_x;
  294.   nlines = 0;
  295.   ncols  = 0;
  296.   if (!PyArg_Parse(arg,
  297.            "(iiii);nlines,ncols,begin_y,begin_x",
  298.            &nlines,&ncols,&begin_y,&begin_x))
  299.     if (!PyArg_Parse(arg,"(ii)",&begin_y,&begin_x))
  300.       return (PyObject *)NULL;
  301.   win = subwin(self->win,nlines,ncols,begin_y,begin_x);
  302.   if (win == NULL) {
  303.     Py_INCREF(Py_None);
  304.     return (PyObject *)Py_None;
  305.   }
  306.   rtn_win = (PyCursesWindowObject *)PyCursesWindow_New(win);
  307.   rtn_win->parent = self->win;
  308.   return (PyObject *)rtn_win;
  309. }
  310.  
  311. static PyObject *
  312. PyCursesWindow_AddCh(self,arg)
  313.      PyCursesWindowObject *self;
  314.      PyObject * arg;
  315. {
  316.   int rtn;
  317.   int x, y;
  318.   int ch;
  319.   int attr;
  320.   int attr_old;
  321.   int use_xy = TRUE;
  322.   int use_attr = TRUE;
  323.   switch (PyTuple_Size(arg)) {
  324.     case 2:
  325.     case 4:
  326.       use_attr = TRUE;
  327.       break;
  328.     default:
  329.       use_attr = FALSE;
  330.     }
  331.   if (!PyArg_Parse(arg,"(iiii);y,x,ch,attr", &y, &x, &ch, &attr)) {
  332.     if (!PyArg_Parse(arg,"(iii);y,x,ch", &y, &x, &ch)) {
  333.       use_xy = FALSE;
  334.       if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
  335.     if (!PyArg_Parse(arg,"i;ch", &ch))
  336.       return (PyObject *)NULL;
  337.     }
  338.   }
  339.   if (use_attr == TRUE) {
  340.     attr_old = getattrs(self->win);
  341.     wattrset(self->win,attr);
  342.   }
  343.   if (use_xy == TRUE)
  344.     rtn = mvwaddch(self->win,y,x,ch);
  345.   else
  346.     rtn = waddch(self->win,ch);
  347.   if (use_attr == TRUE)
  348.     wattrset(self->win,attr_old);
  349.   if (rtn == OK) {
  350.     Py_INCREF(PyCurses_OK);
  351.     return (PyObject *)PyCurses_OK;
  352.   }
  353.   Py_INCREF(PyCurses_ERR);
  354.   return (PyObject *)PyCurses_ERR;
  355. }
  356.  
  357. static PyObject *
  358. PyCursesWindow_InsCh(self,arg)
  359.      PyCursesWindowObject *self;
  360.      PyObject * arg;
  361. {
  362.   int rtn;
  363.   int x, y;
  364.   int ch;
  365.   int use_xy = TRUE;
  366.   int attr, attr_old, use_attr = FALSE;
  367.   switch (PyTuple_Size(arg)) {
  368.     case 2:
  369.     case 4:
  370.       use_attr = TRUE;
  371.       break;
  372.     default:
  373.       use_attr = FALSE;
  374.     }
  375.   if (!PyArg_Parse(arg,"(iiii);y,x,ch,attr", &y, &x, &ch, &attr)) {
  376.     if (!PyArg_Parse(arg,"(iii);y,x,ch", &y, &x, &ch)) {
  377.       use_xy = FALSE;
  378.       if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
  379.     if (!PyArg_Parse(arg,"i;ch", &ch))
  380.       return (PyObject *)NULL;
  381.     }
  382.   }
  383.   if (use_attr == TRUE) {
  384.     attr_old = getattrs(self->win);
  385.     wattrset(self->win,attr);
  386.   }
  387.   if (use_xy == TRUE)
  388.     rtn = mvwinsch(self->win,y,x,ch);
  389.   else
  390.     rtn = winsch(self->win,ch);
  391.   if (use_attr == TRUE)
  392.     wattrset(self->win,attr_old);
  393.   if (rtn == OK) {
  394.     Py_INCREF(PyCurses_OK);
  395.     return (PyObject *)PyCurses_OK;
  396.   }
  397.   Py_INCREF(PyCurses_ERR);
  398.   return (PyObject *)PyCurses_ERR;
  399. }
  400.  
  401. static PyObject *
  402. PyCursesWindow_DelCh(self,arg)
  403.      PyCursesWindowObject *self;
  404.      PyObject * arg;
  405. {
  406.   int rtn;
  407.   int x, y;
  408.   int use_xy = TRUE;
  409.   if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
  410.     use_xy = FALSE;
  411.   PyErr_Clear();
  412.   if (use_xy == TRUE)
  413.     rtn = mvwdelch(self->win,y,x);
  414.   else
  415.     rtn = wdelch(self->win);
  416.   if (rtn == OK) {
  417.     Py_INCREF(PyCurses_OK);
  418.     return (PyObject *)PyCurses_OK;
  419.   }
  420.   Py_INCREF(PyCurses_ERR);
  421.   return (PyObject *)PyCurses_ERR;
  422. }
  423.  
  424. static PyObject *
  425. PyCursesWindow_EchoChar(self,arg)
  426.      PyCursesWindowObject *self;
  427.      PyObject * arg;
  428. {
  429.   int rtn;
  430.   int ch;
  431.   int attr, attr_old, use_attr = TRUE;
  432.   if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr)) {
  433.     use_attr = FALSE;
  434.     if (!PyArg_Parse(arg,"i;ch", &ch))
  435.       return (PyObject *)NULL;
  436.   }
  437.   if (use_attr == TRUE) {
  438.     attr_old = getattrs(self->win);
  439.     wattrset(self->win,attr);
  440.   }
  441.   rtn = wechochar(self->win,ch);
  442.   if (use_attr == TRUE)
  443.     wattrset(self->win,attr_old);
  444.   if (rtn == OK) {
  445.     Py_INCREF(PyCurses_OK);
  446.     return (PyObject *)PyCurses_OK;
  447.   }
  448.   Py_INCREF(PyCurses_ERR);
  449.   return (PyObject *)PyCurses_ERR;
  450. }
  451.  
  452. static PyObject *
  453. PyCursesWindow_AddStr(self,arg)
  454.      PyCursesWindowObject *self;
  455.      PyObject * arg;
  456. {
  457.   int rtn;
  458.   int x, y;
  459.   char *str;
  460.   int use_xy = TRUE;
  461.   int attr, attr_old, use_attr = TRUE;
  462.     switch (PyTuple_Size(arg)) {
  463.     case 2:
  464.     case 4:
  465.       use_attr = TRUE;
  466.       break;
  467.     default:
  468.       use_attr = FALSE;
  469.     }
  470.   if (!PyArg_Parse(arg,"(iisi);y,x,str,attr", &y, &x, &str, &attr)) {
  471.     if (!PyArg_Parse(arg,"(iis);y,x,str", &y, &x, &str)) {
  472.       use_xy = FALSE;
  473.       if (!PyArg_Parse(arg,"(si);str,attr", &str, &attr))
  474.     if (!PyArg_Parse(arg,"s;str", &str))
  475.       return (PyObject *)NULL;
  476.     }
  477.   }
  478.   if (use_attr == TRUE) {
  479.     attr_old = getattrs(self->win);
  480.     wattrset(self->win,attr);
  481.   }
  482.   if (use_xy == TRUE)
  483.     rtn = mvwaddstr(self->win,y,x,str);
  484.   else
  485.     rtn = waddstr(self->win,str);
  486.   if (use_attr == TRUE)
  487.     wattrset(self->win,attr_old);
  488.   if (rtn == OK) {
  489.     Py_INCREF(PyCurses_OK);
  490.     return (PyObject *)PyCurses_OK;
  491.   }
  492.   Py_INCREF(PyCurses_ERR);
  493.   return (PyObject *)PyCurses_ERR;
  494. }
  495.  
  496. static PyObject *
  497. PyCursesWindow_AttrOn(self,arg)
  498.      PyCursesWindowObject *self;
  499.      PyObject * arg;
  500. {
  501.   int rtn;
  502.   int ch;
  503.   if (!PyArg_Parse(arg,"i;attr", &ch))
  504.       return (PyObject *)NULL;
  505.   rtn = wattron(self->win,ch);
  506.   if (rtn == OK) {
  507.     Py_INCREF(PyCurses_OK);
  508.     return (PyObject *)PyCurses_OK;
  509.   }
  510.   Py_INCREF(PyCurses_ERR);
  511.   return (PyObject *)PyCurses_ERR;
  512. }
  513.  
  514. static PyObject *
  515. PyCursesWindow_AttrOff(self,arg)
  516.      PyCursesWindowObject *self;
  517.      PyObject * arg;
  518. {
  519.   int rtn;
  520.   int ch;
  521.   if (!PyArg_Parse(arg,"i;attr", &ch))
  522.       return (PyObject *)NULL;
  523.   rtn = wattroff(self->win,ch);
  524.   if (rtn == OK) {
  525.     Py_INCREF(PyCurses_OK);
  526.     return (PyObject *)PyCurses_OK;
  527.   }
  528.   Py_INCREF(PyCurses_ERR);
  529.   return (PyObject *)PyCurses_ERR;
  530. }
  531.  
  532. static PyObject *
  533. PyCursesWindow_AttrSet(self,arg)
  534.      PyCursesWindowObject *self;
  535.      PyObject * arg;
  536. {
  537.   int rtn;
  538.   int ch;
  539.   if (!PyArg_Parse(arg,"i;attr", &ch))
  540.       return (PyObject *)NULL;
  541.   rtn = wattrset(self->win,ch);
  542.   if (rtn == OK) {
  543.     Py_INCREF(PyCurses_OK);
  544.     return (PyObject *)PyCurses_OK;
  545.   }
  546.   Py_INCREF(PyCurses_ERR);
  547.   return (PyObject *)PyCurses_ERR;
  548. }
  549.  
  550. static PyObject *
  551. PyCursesWindow_StandEnd(self,arg)
  552.      PyCursesWindowObject *self;
  553.      PyObject * arg;
  554. {
  555.   int rtn;
  556.   if (!PyArg_NoArgs(arg))
  557.       return (PyObject *)NULL;
  558.   rtn = wstandend(self->win);
  559.   if (rtn == OK) {
  560.     Py_INCREF(PyCurses_OK);
  561.     return (PyObject *)PyCurses_OK;
  562.   }
  563.   Py_INCREF(PyCurses_ERR);
  564.   return (PyObject *)PyCurses_ERR;
  565. }
  566.  
  567. static PyObject *
  568. PyCursesWindow_StandOut(self,arg)
  569.      PyCursesWindowObject *self;
  570.      PyObject * arg;
  571. {
  572.   int rtn;
  573.   if (!PyArg_NoArgs(arg))
  574.       return (PyObject *)NULL;
  575.   rtn = wstandout(self->win);
  576.   if (rtn == OK) {
  577.     Py_INCREF(PyCurses_OK);
  578.     return (PyObject *)PyCurses_OK;
  579.   }
  580.   Py_INCREF(PyCurses_ERR);
  581.   return (PyObject *)PyCurses_ERR;
  582. }
  583.  
  584. static PyObject *
  585. PyCursesWindow_Box(self,arg)
  586.      PyCursesWindowObject *self;
  587.      PyObject * arg;
  588. {
  589.   int rtn;
  590.   int ch1=0,ch2=0;
  591.   if (!PyArg_Parse(arg,"(ii);vertch,horch", &ch1, &ch2))
  592.     PyErr_Clear();
  593.   rtn = box(self->win,ch1,ch2);
  594.   if (rtn == OK) {
  595.     Py_INCREF(PyCurses_OK);
  596.     return (PyObject *)PyCurses_OK;
  597.   }
  598.   Py_INCREF(PyCurses_ERR);
  599.   return (PyObject *)PyCurses_ERR;
  600. }
  601.  
  602. static PyObject *
  603. PyCursesWindow_Erase(self,arg)
  604.      PyCursesWindowObject *self;
  605.      PyObject * arg;
  606. {
  607.   if (!PyArg_NoArgs(arg))
  608.       return (PyObject *)NULL;
  609.   werase(self->win);
  610.   Py_INCREF(Py_None);
  611.   return (PyObject *)Py_None;
  612. }
  613.  
  614. static PyObject *
  615. PyCursesWindow_DeleteLine(self,arg)
  616.      PyCursesWindowObject *self;
  617.      PyObject * arg;
  618. {
  619.   if (!PyArg_NoArgs(arg))
  620.       return (PyObject *)NULL;
  621.   wdeleteln(self->win);
  622.   Py_INCREF(Py_None);
  623.   return (PyObject *)Py_None;
  624. }
  625.  
  626. static PyObject *
  627. PyCursesWindow_InsertLine(self,arg)
  628.      PyCursesWindowObject *self;
  629.      PyObject * arg;
  630. {
  631.   if (!PyArg_NoArgs(arg))
  632.       return (PyObject *)NULL;
  633.   winsertln(self->win);
  634.   Py_INCREF(Py_None);
  635.   return (PyObject *)Py_None;
  636. }
  637.  
  638. static PyObject *
  639. PyCursesWindow_GetYX(self,arg)
  640.      PyCursesWindowObject *self;
  641.      PyObject * arg;
  642. {
  643.   int x, y;
  644.   if (!PyArg_NoArgs(arg))
  645.       return (PyObject *)NULL;
  646.   getyx(self->win,y,x);
  647.   return (PyObject *)Py_BuildValue("(ii)", y, x);
  648. }
  649.  
  650. static PyObject *
  651. PyCursesWindow_GetBegYX(self,arg)
  652.      PyCursesWindowObject *self;
  653.      PyObject * arg;
  654. {
  655.   int x, y;
  656.   if (!PyArg_NoArgs(arg))
  657.       return (PyObject *)NULL;
  658.   getbegyx(self->win,y,x);
  659.   return (PyObject *)Py_BuildValue("(ii)", y, x);
  660. }
  661.  
  662. static PyObject *
  663. PyCursesWindow_GetMaxYX(self,arg)
  664.      PyCursesWindowObject *self;
  665.      PyObject * arg;
  666. {
  667.   int x, y;
  668.   if (!PyArg_NoArgs(arg))
  669.       return (PyObject *)NULL;
  670.   getmaxyx(self->win,y,x);
  671.   return (PyObject *)Py_BuildValue("(ii)", y, x);
  672. }
  673.  
  674. static PyObject *
  675. PyCursesWindow_Clear(self,arg)
  676.      PyCursesWindowObject *self;
  677.      PyObject * arg;
  678. {
  679.   if (!PyArg_NoArgs(arg))
  680.       return (PyObject *)NULL;
  681.   wclear(self->win);
  682.   Py_INCREF(Py_None);
  683.   return (PyObject *)Py_None;
  684. }
  685.  
  686. static PyObject *
  687. PyCursesWindow_ClearToBottom(self,arg)
  688.      PyCursesWindowObject *self;
  689.      PyObject * arg;
  690. {
  691.   if (!PyArg_NoArgs(arg))
  692.       return (PyObject *)NULL;
  693.   wclrtobot(self->win);
  694.   Py_INCREF(Py_None);
  695.   return (PyObject *)Py_None;
  696. }
  697.  
  698. static PyObject *
  699. PyCursesWindow_ClearToEOL(self,arg)
  700.      PyCursesWindowObject *self;
  701.      PyObject * arg;
  702. {
  703.   if (!PyArg_NoArgs(arg))
  704.       return (PyObject *)NULL;
  705.   wclrtoeol(self->win);
  706.   Py_INCREF(Py_None);
  707.   return (PyObject *)Py_None;
  708. }
  709.  
  710. static PyObject *
  711. PyCursesWindow_Scroll(self,arg)
  712.      PyCursesWindowObject *self;
  713.      PyObject * arg;
  714. {
  715.   if (!PyArg_NoArgs(arg))
  716.       return (PyObject *)NULL;
  717.   scroll(self->win);
  718.   Py_INCREF(Py_None);
  719.   return (PyObject *)Py_None;
  720. }
  721.  
  722. static PyObject *
  723. PyCursesWindow_TouchWin(self,arg)
  724.      PyCursesWindowObject *self;
  725.      PyObject * arg;
  726. {
  727.   if (!PyArg_NoArgs(arg))
  728.       return (PyObject *)NULL;
  729.   touchwin(self->win);
  730.   Py_INCREF(Py_None);
  731.   return (PyObject *)Py_None;
  732. }
  733.  
  734. static PyObject *
  735. PyCursesWindow_TouchLine(self,arg)
  736.      PyCursesWindowObject *self;
  737.      PyObject * arg;
  738. {
  739.   int st, cnt;
  740.   if (!PyArg_Parse(arg,"(ii);start, count",&st,&cnt))
  741.       return (PyObject *)NULL;
  742.   touchline(self->win,st,cnt);
  743.   Py_INCREF(Py_None);
  744.   return (PyObject *)Py_None;
  745. }
  746.  
  747. static PyObject *
  748. PyCursesWindow_GetCh(self,arg)
  749.      PyCursesWindowObject *self;
  750.      PyObject * arg;
  751. {
  752.   int x, y;
  753.   int use_xy = TRUE;
  754.   int rtn;
  755.   if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
  756.     use_xy = FALSE;
  757.   PyErr_Clear();
  758.   if (use_xy == TRUE)
  759.     rtn = mvwgetch(self->win,y,x);
  760.   else
  761.     rtn = wgetch(self->win);
  762.   return (PyObject *)PyInt_FromLong(rtn);
  763. }
  764.  
  765. static PyObject *
  766. PyCursesWindow_GetStr(self,arg)
  767.      PyCursesWindowObject *self;
  768.      PyObject * arg;
  769. {
  770.   int x, y;
  771.   int use_xy = TRUE;
  772.   char rtn[1024]; /* This should be big enough.. I hope */
  773.   int rtn2;
  774.   if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
  775.     use_xy = FALSE;
  776.   PyErr_Clear();
  777.   if (use_xy == TRUE)
  778.     rtn2 = mvwgetstr(self->win,y,x,rtn);
  779.   else
  780.     rtn2 = wgetstr(self->win,rtn);
  781.   if (rtn2 == ERR)
  782.     rtn[0] = 0;
  783.   return (PyObject *)PyString_FromString(rtn);
  784. }
  785.  
  786. static PyObject *
  787. PyCursesWindow_InCh(self,arg)
  788.      PyCursesWindowObject *self;
  789.      PyObject * arg;
  790. {
  791.   int x, y;
  792.   int use_xy = TRUE;
  793.   int rtn;
  794.   if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
  795.     use_xy = FALSE;
  796.   PyErr_Clear();
  797.   if (use_xy == TRUE)
  798.     rtn = mvwinch(self->win,y,x);
  799.   else
  800.     rtn = winch(self->win);
  801.   return (PyObject *)PyInt_FromLong(rtn);
  802. }
  803.  
  804. static PyObject *
  805. PyCursesWindow_ClearOk(self,arg)
  806.      PyCursesWindowObject *self;
  807.      PyObject * arg;
  808. {
  809.   int val;
  810.   if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
  811.     return (PyObject *)NULL;
  812.   clearok(self->win,val);
  813.   Py_INCREF(Py_None);
  814.   return (PyObject *)Py_None;
  815. }
  816.  
  817. static PyObject *
  818. PyCursesWindow_IdlOk(self,arg)
  819.      PyCursesWindowObject *self;
  820.      PyObject * arg;
  821. {
  822.   int val;
  823.   if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
  824.     return (PyObject *)NULL;
  825.   idlok(self->win,val);
  826.   Py_INCREF(Py_None);
  827.   return (PyObject *)Py_None;
  828. }
  829.  
  830. static PyObject *
  831. PyCursesWindow_LeaveOk(self,arg)
  832.      PyCursesWindowObject *self;
  833.      PyObject * arg;
  834. {
  835.   int val;
  836.   if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
  837.     return (PyObject *)NULL;
  838.   leaveok(self->win,val);
  839.   Py_INCREF(Py_None);
  840.   return (PyObject *)Py_None;
  841. }
  842.  
  843. static PyObject *
  844. PyCursesWindow_ScrollOk(self,arg)
  845.      PyCursesWindowObject *self;
  846.      PyObject * arg;
  847. {
  848.   int val;
  849.   if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
  850.     return (PyObject *)NULL;
  851.   scrollok(self->win,val);
  852.   Py_INCREF(Py_None);
  853.   return (PyObject *)Py_None;
  854. }
  855.  
  856. static PyObject *
  857. PyCursesWindow_SetScrollRegion(self,arg)
  858.      PyCursesWindowObject *self;
  859.      PyObject * arg;
  860. {
  861.   int x, y;
  862.   if (!PyArg_Parse(arg,"(ii);top, bottom",&y,&x))
  863.     return (PyObject *)NULL;
  864.   wsetscrreg(self->win,y,x);
  865.   Py_INCREF(Py_None);
  866.   return (PyObject *)Py_None;
  867. }
  868.  
  869. static PyObject *
  870. PyCursesWindow_KeyPad(self,arg)
  871.      PyCursesWindowObject * self;
  872.      PyObject * arg;
  873. {
  874.   int ch;
  875.   if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
  876.     return (PyObject *)NULL;
  877.   keypad(self->win,ch);
  878.   Py_INCREF(Py_None);
  879.   return (PyObject *)Py_None;
  880. }
  881.  
  882. static PyObject *
  883. PyCursesWindow_NoDelay(self,arg)
  884.      PyCursesWindowObject * self;
  885.      PyObject * arg;
  886. {
  887.   int ch;
  888.   if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
  889.     return (PyObject *)NULL;
  890.   nodelay(self->win,ch);
  891.   Py_INCREF(Py_None);
  892.   return (PyObject *)Py_None;
  893. }
  894.  
  895. static PyObject *
  896. PyCursesWindow_NoTimeout(self,arg)
  897.      PyCursesWindowObject * self;
  898.      PyObject * arg;
  899. {
  900.   int ch;
  901.   if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
  902.     return (PyObject *)NULL;
  903.   notimeout(self->win,ch);
  904.   Py_INCREF(Py_None);
  905.   return (PyObject *)Py_None;
  906. }
  907.  
  908. static PyMethodDef PyCursesWindow_Methods[] = {
  909.     {"refresh",             (PyCFunction)PyCursesWindow_Refresh},
  910.     {"nooutrefresh",        (PyCFunction)PyCursesWindow_NoOutRefresh},
  911.     {"mvwin",               (PyCFunction)PyCursesWindow_MoveWin},
  912.     {"move",                (PyCFunction)PyCursesWindow_Move},
  913.     {"subwin",              (PyCFunction)PyCursesWindow_SubWin},
  914.     {"addch",               (PyCFunction)PyCursesWindow_AddCh},
  915.     {"insch",               (PyCFunction)PyCursesWindow_InsCh},
  916.     {"delch",               (PyCFunction)PyCursesWindow_DelCh},
  917.     {"echochar",            (PyCFunction)PyCursesWindow_EchoChar},
  918.     {"addstr",              (PyCFunction)PyCursesWindow_AddStr},
  919.     {"attron",              (PyCFunction)PyCursesWindow_AttrOn},
  920.     {"attroff",             (PyCFunction)PyCursesWindow_AttrOff},
  921.     {"attrset",             (PyCFunction)PyCursesWindow_AttrSet},
  922.     {"standend",            (PyCFunction)PyCursesWindow_StandEnd},
  923.     {"standout",            (PyCFunction)PyCursesWindow_StandOut},
  924.     {"box",                 (PyCFunction)PyCursesWindow_Box},
  925.     {"erase",               (PyCFunction)PyCursesWindow_Erase},
  926.     {"deleteln",            (PyCFunction)PyCursesWindow_DeleteLine},
  927.     {"insertln",            (PyCFunction)PyCursesWindow_InsertLine},
  928.     {"getyx",               (PyCFunction)PyCursesWindow_GetYX},
  929.     {"getbegyx",            (PyCFunction)PyCursesWindow_GetBegYX},
  930.     {"getmaxyx",            (PyCFunction)PyCursesWindow_GetMaxYX},
  931.     {"clear",               (PyCFunction)PyCursesWindow_Clear},
  932.     {"clrtobot",            (PyCFunction)PyCursesWindow_ClearToBottom},
  933.     {"clrtoeol",            (PyCFunction)PyCursesWindow_ClearToEOL},
  934.     {"scroll",              (PyCFunction)PyCursesWindow_Scroll},
  935.     {"touchwin",            (PyCFunction)PyCursesWindow_TouchWin},
  936.     {"touchline",           (PyCFunction)PyCursesWindow_TouchLine},
  937.     {"getch",               (PyCFunction)PyCursesWindow_GetCh},
  938.     {"getstr",              (PyCFunction)PyCursesWindow_GetStr},
  939.     {"inch",                (PyCFunction)PyCursesWindow_InCh},
  940.     {"clearok",             (PyCFunction)PyCursesWindow_ClearOk},
  941.     {"idlok",               (PyCFunction)PyCursesWindow_IdlOk},
  942.     {"leaveok",             (PyCFunction)PyCursesWindow_LeaveOk},
  943.     {"scrollok",            (PyCFunction)PyCursesWindow_ScrollOk},
  944.     {"setscrreg",           (PyCFunction)PyCursesWindow_SetScrollRegion},
  945.     {"keypad",              (PyCFunction)PyCursesWindow_KeyPad},
  946.     {"nodelay",             (PyCFunction)PyCursesWindow_NoDelay},
  947.     {"notimeout",           (PyCFunction)PyCursesWindow_NoTimeout},
  948.     {NULL,                (PyCFunction)NULL}   /* sentinel */
  949. };
  950.  
  951. static PyObject *
  952. PyCursesWindow_GetAttr(self, name)
  953.     PyCursesWindowObject *self;
  954.     char *name;
  955. {
  956.   return findmethod(PyCursesWindow_Methods, (PyObject *)self, name);
  957. }
  958.  
  959. /* --------------- PAD routines ---------------- */
  960. static PyObject *
  961. PyCursesPad_New(pad)
  962.     WINDOW *pad;
  963. {
  964.     PyCursesPadObject *po;
  965.     po = (PyCursesPadObject *)PyObject_NEW(PyCursesPadObject, &PyCursesPad_Type);
  966.     if (po == NULL)
  967.         return NULL;
  968.     po->pad = pad;
  969.     return (PyObject *)po;
  970. }
  971.  
  972. /* -------------------------------------------------------*/
  973. static PyTypeObject PyCursesScreen_Type = {
  974.     PyObject_HEAD_INIT(&PyType_Type)
  975.     0,            /*ob_size*/
  976.     "curses screen",    /*tp_name*/
  977.     sizeof(PyCursesScreenObject),    /*tp_basicsize*/
  978.     0,            /*tp_itemsize*/
  979.     /* methods */
  980.     (destructor)0 /*PyCursesScreen_Dealloc*/, /*tp_dealloc*/
  981.     0,            /*tp_print*/
  982.     (getattrfunc)0, /*tp_getattr*/
  983.     (setattrfunc)0, /*tp_setattr*/
  984.     0,            /*tp_compare*/
  985.     0,            /*tp_repr*/
  986.     0,            /*tp_as_number*/
  987.     0,            /*tp_as_sequence*/
  988.     0,            /*tp_as_mapping*/
  989.     0,            /*tp_hash*/
  990. };
  991.  
  992. static PyTypeObject PyCursesWindow_Type = {
  993.     PyObject_HEAD_INIT(&PyType_Type)
  994.     0,            /*ob_size*/
  995.     "curses window",    /*tp_name*/
  996.     sizeof(PyCursesWindowObject),    /*tp_basicsize*/
  997.     0,            /*tp_itemsize*/
  998.     /* methods */
  999.     (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
  1000.     0,            /*tp_print*/
  1001.     (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/
  1002.     (setattrfunc)0, /*tp_setattr*/
  1003.     0,            /*tp_compare*/
  1004.     0,            /*tp_repr*/
  1005.     0,            /*tp_as_number*/
  1006.     0,            /*tp_as_sequence*/
  1007.     0,            /*tp_as_mapping*/
  1008.     0,            /*tp_hash*/
  1009. };
  1010.  
  1011. static PyTypeObject PyCursesPad_Type = {
  1012.     PyObject_HEAD_INIT(&PyType_Type)
  1013.     0,            /*ob_size*/
  1014.     "curses pad",    /*tp_name*/
  1015.     sizeof(PyCursesPadObject),    /*tp_basicsize*/
  1016.     0,            /*tp_itemsize*/
  1017.     /* methods */
  1018.     (destructor)0 /*PyCursesPad_Dealloc*/, /*tp_dealloc*/
  1019.     0,            /*tp_print*/
  1020.     (getattrfunc)0, /*tp_getattr*/
  1021.     (setattrfunc)0, /*tp_setattr*/
  1022.     0,            /*tp_compare*/
  1023.     0,            /*tp_repr*/
  1024.     0,            /*tp_as_number*/
  1025.     0,            /*tp_as_sequence*/
  1026.     0,            /*tp_as_mapping*/
  1027.     0,            /*tp_hash*/
  1028. };
  1029.  
  1030. /* -------------------------------------------------------*/
  1031.  
  1032. static PyObject *ModDict;
  1033.  
  1034. static PyObject * 
  1035. PyCurses_InitScr(self, args)
  1036.      PyObject * self;
  1037.      PyObject * args;
  1038. {
  1039.   static int already_inited = FALSE;
  1040.   WINDOW *win;
  1041.   if (!PyArg_NoArgs(args))
  1042.     return (PyObject *)NULL;
  1043.   if (already_inited == TRUE) {
  1044.     wrefresh(stdscr);
  1045.     return (PyObject *)PyCursesWindow_New(stdscr);
  1046.   }
  1047.   already_inited = TRUE;
  1048.  
  1049.   win = initscr();
  1050.  
  1051. /* This was moved from initcurses() because core dumped on SGI */
  1052. #define SetDictChar(string,ch) \
  1053.     PyDict_SetItemString(ModDict,string,PyInt_FromLong(ch));
  1054.  
  1055.     /* Here are some graphic symbols you can use */
  1056.         SetDictChar("ACS_ULCORNER",(ACS_ULCORNER));
  1057.     SetDictChar("ACS_ULCORNER",(ACS_ULCORNER));
  1058.     SetDictChar("ACS_LLCORNER",(ACS_LLCORNER));
  1059.     SetDictChar("ACS_URCORNER",(ACS_URCORNER));
  1060.     SetDictChar("ACS_LRCORNER",(ACS_LRCORNER));
  1061.     SetDictChar("ACS_RTEE",    (ACS_RTEE));
  1062.     SetDictChar("ACS_LTEE",    (ACS_LTEE));
  1063.     SetDictChar("ACS_BTEE",    (ACS_BTEE));
  1064.     SetDictChar("ACS_TTEE",    (ACS_TTEE));
  1065.     SetDictChar("ACS_HLINE",   (ACS_HLINE));
  1066.     SetDictChar("ACS_VLINE",   (ACS_VLINE));
  1067.     SetDictChar("ACS_PLUS",    (ACS_PLUS));
  1068.     SetDictChar("ACS_S1",      (ACS_S1));
  1069.     SetDictChar("ACS_S9",      (ACS_S9));
  1070.     SetDictChar("ACS_DIAMOND", (ACS_DIAMOND));
  1071.     SetDictChar("ACS_CKBOARD", (ACS_CKBOARD));
  1072.     SetDictChar("ACS_DEGREE",  (ACS_DEGREE));
  1073.     SetDictChar("ACS_PLMINUS", (ACS_PLMINUS));
  1074.     SetDictChar("ACS_BULLET",  (ACS_BULLET));
  1075.     SetDictChar("ACS_LARROW",  (ACS_RARROW));
  1076.     SetDictChar("ACS_DARROW",  (ACS_DARROW));
  1077.     SetDictChar("ACS_UARROW",  (ACS_UARROW));
  1078.     SetDictChar("ACS_BOARD",   (ACS_BOARD));
  1079.     SetDictChar("ACS_LANTERN", (ACS_LANTERN));
  1080.     SetDictChar("ACS_BLOCK",   (ACS_BLOCK));
  1081.  
  1082.   return (PyObject *)PyCursesWindow_New(win);
  1083. }
  1084.  
  1085. static PyObject * 
  1086. PyCurses_EndWin(self, args)
  1087.      PyObject * self;
  1088.      PyObject * args;
  1089. {
  1090.   if (!PyArg_NoArgs(args))
  1091.     return (PyObject *)NULL;
  1092.   endwin();
  1093.   Py_INCREF(Py_None);
  1094.   return Py_None;
  1095. }
  1096.  
  1097. static PyObject * 
  1098. PyCurses_IsEndWin(self, args)
  1099.      PyObject * self;
  1100.      PyObject * args;
  1101. {
  1102.   if (!PyArg_NoArgs(args))
  1103.     return (PyObject *)NULL;
  1104.   if (isendwin() == FALSE) {
  1105.     Py_INCREF(Py_False);
  1106.     return Py_False;
  1107.   }
  1108.   Py_INCREF(Py_True);
  1109.   return Py_True;
  1110. }
  1111.  
  1112. static PyObject *
  1113. PyCurses_DoUpdate(self,arg)
  1114.      PyObject * self;
  1115.      PyObject * arg;
  1116. {
  1117.   if (!PyArg_NoArgs(arg))
  1118.     return (PyObject *)NULL;
  1119.   return (PyObject *)PyInt_FromLong(doupdate());
  1120. }
  1121.  
  1122. static PyObject *
  1123. PyCurses_NewWindow(self,arg)
  1124.      PyObject * self;
  1125.      PyObject * arg;
  1126. {
  1127.   WINDOW *win;
  1128.   int nlines, ncols, begin_y, begin_x;
  1129.   nlines = 0;
  1130.   ncols  = 0;
  1131.   if (!PyArg_Parse(arg,
  1132.            "(iiii);nlines,ncols,begin_y,begin_x",
  1133.            &nlines,&ncols,&begin_y,&begin_x))
  1134.     if (!PyArg_Parse(arg,"(ii)",&begin_y,&begin_x))
  1135.       return (PyObject *)NULL;
  1136.   win = newwin(nlines,ncols,begin_y,begin_x);
  1137.   if (win == NULL) {
  1138.     Py_INCREF(Py_None);
  1139.     return (PyObject *)Py_None;
  1140.   }
  1141.   return (PyObject *)PyCursesWindow_New(win);
  1142. }
  1143.  
  1144. static PyObject *
  1145. PyCurses_Beep(self,arg)
  1146.      PyObject * self;
  1147.      PyObject * arg;
  1148. {
  1149.   if (!PyArg_NoArgs(arg))
  1150.     return (PyObject *)NULL;
  1151.   beep();
  1152.   Py_INCREF(Py_None);
  1153.   return (PyObject *)Py_None;
  1154. }
  1155.  
  1156. static PyObject *
  1157. PyCurses_Flash(self,arg)
  1158.      PyObject * self;
  1159.      PyObject * arg;
  1160. {
  1161.   if (!PyArg_NoArgs(arg))
  1162.     return (PyObject *)NULL;
  1163.   flash();
  1164.   Py_INCREF(Py_None);
  1165.   return (PyObject *)Py_None;
  1166. }
  1167.  
  1168. static PyObject *
  1169. PyCurses_UngetCh(self,arg)
  1170.      PyObject * self;
  1171.      PyObject * arg;
  1172. {
  1173.   int ch;
  1174.   if (!PyArg_Parse(arg,"i;integer",&ch))
  1175.     return (PyObject *)NULL;
  1176.   ungetch(ch);
  1177.   Py_INCREF(Py_None);
  1178.   return (PyObject *)Py_None;
  1179. }
  1180.  
  1181. static PyObject *
  1182. PyCurses_FlushInp(self,arg)
  1183.      PyObject * self;
  1184.      PyObject * arg;
  1185. {
  1186.   if (!PyArg_NoArgs(arg))
  1187.     return (PyObject *)NULL;
  1188.   flushinp();
  1189.   Py_INCREF(Py_None);
  1190.   return (PyObject *)Py_None;
  1191. }
  1192.  
  1193. static PyObject *
  1194. PyCurses_CBreak(self,arg)
  1195.      PyObject * self;
  1196.      PyObject * arg;
  1197. {
  1198.   if (!PyArg_NoArgs(arg))
  1199.     return (PyObject *)NULL;
  1200.   cbreak();
  1201.   Py_INCREF(Py_None);
  1202.   return (PyObject *)Py_None;
  1203. }
  1204.  
  1205. static PyObject *
  1206. PyCurses_NoCBreak(self,arg)
  1207.      PyObject * self;
  1208.      PyObject * arg;
  1209. {
  1210.   if (!PyArg_NoArgs(arg))
  1211.     return (PyObject *)NULL;
  1212.   nocbreak();
  1213.   Py_INCREF(Py_None);
  1214.   return (PyObject *)Py_None;
  1215. }
  1216.  
  1217. static PyObject *
  1218. PyCurses_Echo(self,arg)
  1219.      PyObject * self;
  1220.      PyObject * arg;
  1221. {
  1222.   if (!PyArg_NoArgs(arg))
  1223.     return (PyObject *)NULL;
  1224.   echo();
  1225.   Py_INCREF(Py_None);
  1226.   return (PyObject *)Py_None;
  1227. }
  1228.  
  1229. static PyObject *
  1230. PyCurses_NoEcho(self,arg)
  1231.      PyObject * self;
  1232.      PyObject * arg;
  1233. {
  1234.   if (!PyArg_NoArgs(arg))
  1235.     return (PyObject *)NULL;
  1236.   noecho();
  1237.   Py_INCREF(Py_None);
  1238.   return (PyObject *)Py_None;
  1239. }
  1240.  
  1241. static PyObject *
  1242. PyCurses_Nl(self,arg)
  1243.      PyObject * self;
  1244.      PyObject * arg;
  1245. {
  1246.   if (!PyArg_NoArgs(arg))
  1247.     return (PyObject *)NULL;
  1248.   nl();
  1249.   Py_INCREF(Py_None);
  1250.   return (PyObject *)Py_None;
  1251. }
  1252.  
  1253. static PyObject *
  1254. PyCurses_NoNl(self,arg)
  1255.      PyObject * self;
  1256.      PyObject * arg;
  1257. {
  1258.   if (!PyArg_NoArgs(arg))
  1259.     return (PyObject *)NULL;
  1260.   nonl();
  1261.   Py_INCREF(Py_None);
  1262.   return (PyObject *)Py_None;
  1263. }
  1264.  
  1265. static PyObject *
  1266. PyCurses_Raw(self,arg)
  1267.      PyObject * self;
  1268.      PyObject * arg;
  1269. {
  1270.   if (!PyArg_NoArgs(arg))
  1271.     return (PyObject *)NULL;
  1272.   raw();
  1273.   Py_INCREF(Py_None);
  1274.   return (PyObject *)Py_None;
  1275. }
  1276.  
  1277. static PyObject *
  1278. PyCurses_NoRaw(self,arg)
  1279.      PyObject * self;
  1280.      PyObject * arg;
  1281. {
  1282.   if (!PyArg_NoArgs(arg))
  1283.     return (PyObject *)NULL;
  1284.   noraw();
  1285.   Py_INCREF(Py_None);
  1286.   return (PyObject *)Py_None;
  1287. }
  1288.  
  1289. static PyObject *
  1290. PyCurses_IntrFlush(self,arg)
  1291.      PyObject * self;
  1292.      PyObject * arg;
  1293. {
  1294.   int ch;
  1295.   if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
  1296.     return (PyObject *)NULL;
  1297.   intrflush(NULL,ch);
  1298.   Py_INCREF(Py_None);
  1299.   return (PyObject *)Py_None;
  1300. }
  1301.  
  1302. static PyObject *
  1303. PyCurses_Meta(self,arg)
  1304.      PyObject * self;
  1305.      PyObject * arg;
  1306. {
  1307.   int ch;
  1308.   if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
  1309.     return (PyObject *)NULL;
  1310.   meta(NULL,ch);
  1311.   Py_INCREF(Py_None);
  1312.   return (PyObject *)Py_None;
  1313. }
  1314.  
  1315. static PyObject *
  1316. PyCurses_KeyName(self,arg)
  1317.      PyObject * self;
  1318.      PyObject * arg;
  1319. {
  1320.   int ch;
  1321.   if (!PyArg_Parse(arg,"i",&ch))
  1322.     return (PyObject *)NULL;
  1323.   return PyString_FromString((char *)keyname(ch));
  1324. }
  1325.  
  1326. #ifdef NOT_YET
  1327. static PyObject * 
  1328. PyCurses_NewTerm(self, args)
  1329.      PyObject * self;
  1330.      PyObject * args;
  1331. {
  1332. }
  1333.  
  1334. static PyObject * 
  1335. PyCurses_SetTerm(self, args)
  1336.      PyObject * self;
  1337.      PyObject * args;
  1338. {
  1339. }
  1340. #endif
  1341.  
  1342. /* List of functions defined in the module */
  1343.  
  1344. static PyMethodDef PyCurses_methods[] = {
  1345.     {"initscr",             (PyCFunction)PyCurses_InitScr},
  1346.     {"endwin",              (PyCFunction)PyCurses_EndWin},
  1347.     {"isendwin",            (PyCFunction)PyCurses_IsEndWin},
  1348.     {"doupdate",            (PyCFunction)PyCurses_DoUpdate},
  1349.     {"newwin",              (PyCFunction)PyCurses_NewWindow},
  1350.     {"beep",                (PyCFunction)PyCurses_Beep},
  1351.     {"flash",               (PyCFunction)PyCurses_Flash},
  1352.     {"ungetch",             (PyCFunction)PyCurses_UngetCh},
  1353.     {"flushinp",            (PyCFunction)PyCurses_FlushInp},
  1354.     {"cbreak",              (PyCFunction)PyCurses_CBreak},
  1355.     {"nocbreak",            (PyCFunction)PyCurses_NoCBreak},
  1356.     {"echo",                (PyCFunction)PyCurses_Echo},
  1357.     {"noecho",              (PyCFunction)PyCurses_NoEcho},
  1358.     {"nl",                  (PyCFunction)PyCurses_Nl},
  1359.     {"nonl",                (PyCFunction)PyCurses_NoNl},
  1360.     {"raw",                 (PyCFunction)PyCurses_Raw},
  1361.     {"noraw",               (PyCFunction)PyCurses_NoRaw},
  1362.     {"intrflush",           (PyCFunction)PyCurses_IntrFlush},
  1363.     {"meta",                (PyCFunction)PyCurses_Meta},
  1364.     {"keyname",             (PyCFunction)PyCurses_KeyName},
  1365. #ifdef NOT_YET
  1366.     {"newterm",             (PyCFunction)PyCurses_NewTerm},
  1367.     {"set_term",            (PyCFunction)PyCurses_SetTerm},
  1368. #endif
  1369.     {NULL,        NULL}        /* sentinel */
  1370. };
  1371.  
  1372. /* Initialization function for the module */
  1373.  
  1374. void
  1375. initcurses()
  1376. {
  1377.     PyObject *m, *d, *x;
  1378.  
  1379.     /* Create the module and add the functions */
  1380.     m = Py_InitModule("curses", PyCurses_methods);
  1381.  
  1382.     PyCurses_OK  = Py_True;
  1383.     PyCurses_ERR = Py_False;
  1384.     Py_INCREF(PyCurses_OK);
  1385.     Py_INCREF(PyCurses_ERR);
  1386.     /* Add some symbolic constants to the module */
  1387.     d = PyModule_GetDict(m);
  1388.     ModDict = d; /* For PyCurses_InitScr */
  1389.  
  1390.     /* Make the version available */
  1391.     PyDict_SetItemString(d,"version",
  1392.                  PyString_FromString(PyCursesVersion));
  1393.  
  1394.     /* Here are some defines */
  1395.     PyDict_SetItemString(d,"OK", PyCurses_OK);
  1396.     PyDict_SetItemString(d,"ERR",PyCurses_ERR);
  1397.  
  1398.     /* Here are some attributes you can add to chars to print */
  1399.     PyDict_SetItemString(d, "A_NORMAL",    PyInt_FromLong(A_NORMAL));
  1400.     PyDict_SetItemString(d, "A_STANDOUT",  PyInt_FromLong(A_STANDOUT));
  1401.     PyDict_SetItemString(d, "A_UNDERLINE", PyInt_FromLong(A_UNDERLINE));
  1402.     PyDict_SetItemString(d, "A_REVERSE",   PyInt_FromLong(A_REVERSE));
  1403.     PyDict_SetItemString(d, "A_BLINK",     PyInt_FromLong(A_BLINK));
  1404.     PyDict_SetItemString(d, "A_DIM",       PyInt_FromLong(A_DIM));
  1405.     PyDict_SetItemString(d, "A_BOLD",      PyInt_FromLong(A_BOLD));
  1406.     PyDict_SetItemString(d, "A_ALTCHARSET",PyInt_FromLong(A_ALTCHARSET));
  1407.  
  1408.     /* Now set everything up for KEY_ variables */
  1409.     {
  1410.       int key;
  1411.       char *key_n;
  1412.       char *key_n2;
  1413.       for (key=KEY_MIN;key < KEY_MAX; key++) {
  1414.         key_n = (char *)keyname(key);
  1415.         if (strcmp(key_n,"UNKNOWN KEY")==0)
  1416.           continue;
  1417.         if (strncmp(key_n,"KEY_F(",6)==0) {
  1418.           char *p1, *p2;
  1419.           key_n2 = malloc(strlen(key_n)+1);
  1420.           p1 = key_n;
  1421.           p2 = key_n2;
  1422.           while (*p1) {
  1423.         if (*p1 != '(' && *p1 != ')') {
  1424.           *p2 = *p1;
  1425.           p2++;
  1426.         }
  1427.         p1++;
  1428.           }
  1429.           *p2 = (char)0;
  1430.         } else
  1431.           key_n2 = key_n;
  1432.         PyDict_SetItemString(d,key_n2,PyInt_FromLong(key));
  1433.         if (key_n2 != key_n)
  1434.           free(key_n2);
  1435.       }
  1436.     SetDictChar("KEY_MIN",KEY_MIN);
  1437.     SetDictChar("KEY_MAX",KEY_MAX);
  1438.     }
  1439.  
  1440.     /* Check for errors */
  1441.     if (PyErr_Occurred())
  1442.         Py_FatalError("can't initialize module syslog");
  1443. }
  1444.